package com.ss.android.action.a;

import android.content.Context;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.Logger;
import com.ss.android.account.Spipe;
import com.ss.android.action.a.a.Comment;
import com.ss.android.common.AbsApiThread;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.http.legacy.a.NameValueImpl;
import com.ss.android.model.BaseArticle;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;

public final class CommentActionThread extends AbsApiThread {
    private final CommentAction mCommentAction;
    private final BaseArticle b;
    private final Context mContext;

    public CommentActionThread(Context context, String action, Comment comment, BaseArticle arg8) {
        super("CommentActionThread");
        this.mContext = context.getApplicationContext();
        new WeakReference(comment);
        this.mCommentAction = new CommentAction(action, comment.commentId);
        this.b = arg8;
    }

    public final void run() {
        try {
            if(android.support.design.a.isTextEmpty(this.mCommentAction.action)) {
                return;
            }

            ArrayList v0_1 = new ArrayList();
            ((List)v0_1).add(new NameValueImpl("comment_id", String.valueOf(this.mCommentAction.commentId)));
            ((List)v0_1).add(new NameValueImpl("action", this.mCommentAction.action));
            if(this.b != null && this.b.groupId > 0) {
                ((List)v0_1).add(new NameValueImpl("group_id", String.valueOf(this.b.groupId)));
                ((List)v0_1).add(new NameValueImpl("item_id", String.valueOf(this.b.itemId)));
                ((List)v0_1).add(new NameValueImpl("aggr_type", String.valueOf(this.b.aggrType)));
            }

            String v0_2 = NetworkUtils.executePost(8192, Spipe.dataCommentActionUrl, ((List)v0_1));
            if(v0_2 == null) {
                return;
            }

            if(v0_2.length() == 0) {
                return;
            }

            JSONObject v1 = new JSONObject(v0_2);
            this.mCommentAction.isApiSuccess = AbsApiThread.isApiSuccess(v1);
            if(!this.mCommentAction.isApiSuccess) {
                Logger.d("snssdk", "comment_action error: " + v0_2);
                return;
            }

            this.mCommentAction.actionExist = v1.optString("action_exist");
            if(!android.support.design.a.isTextEmpty(this.mCommentAction.actionExist)) {
                this.mCommentAction.isApiSuccess = false;
            }

            v1.optInt("digg_count", -1);
            v1.optInt("bury_count", -1);
            v1.optInt("user_digg", -1);
            v1.optInt("user_bury", -1);
        }
        catch(Throwable v0) {
            TTUtils.getErrorCode(this.mContext, v0);
        }
    }
}

